package com.swq.java.code.chapter17.code05;

import java.util.*;

public class SortTester {
    public static void main(String[] args) {
        String[] data = {"Tom", "Mike", "Mary", "Linda", "Jack"};
        List<String> names = Arrays.asList(data);

        //方式一：通过创建匿名的Comparator实例来排序
        Comparator<String> cp = new Comparator<String>() {
            public int compare(String s1, String s2) {
                return (s1.compareTo(s2));
            }
        };
        Collections.sort(names, cp);

        //方式二：用Lambda表达式来排序
        Comparator<String> sortByName = (String s1, String s2) -> (s1.compareTo(s2));
        Collections.sort(names, sortByName);

        //方式三：用Lambda表达式来排序
        Collections.sort(names, (String s1, String s2) -> (s1.compareTo(s2)));

        names.forEach(System.out::println);
    }
}
